<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <input type='hidden' name='contactId' id='contactId' value="">
                    <input type='hidden' name='type' id='type' value="">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
<!--	                   			<td>-->
<!--		                   			<form class="form-inline" onsubmit="return false">-->
<!--										<div class="form-group">-->
<!--											id：-->
<!--											<input id="id" type="text" class="form-control" placeholder="id">-->
<!--											<button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>-->
<!--										</div>-->
<!--									</form>-->
<!--	                   			</td>-->
	                   			<td align="left">
	                   				<button class="layui-btn layui-btn-sm" onclick="toAdd()">
                                      <i class="layui-icon">&#xe608;</i> 添加
                                    </button>
	                   			</td>
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
                                    <th>id</th>
                                	<th>contactId</th>
<!--									<th>createDate</th>-->
<!--									<th>creater</th>-->
<!--									<th>modifyDate</th>-->
<!--									<th>modifyer</th>-->
									<th>姓名</th>
									<th>影响干系人关系</th>
                                    <th>事件</th>
                                <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
var pers = checkPermission();
var example;
function init(){
    var contactId = getUrlParam("contactId");
    var type = getUrlParam("type");
    $("#type").val(type);
    $("#contactId").val(contactId);
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/customContactStakeholder/getInfoList",
        		"type":"get",
        		"data":function(d){
    				d.id = $("#id").val();
                    d.contactId = $("#contactId").val();
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
                {"data" : "id", "defaultContent" : "","visible" : false},
                {"data" : "contactId", "defaultContent" : "","visible" : false},
				// {"data" : "createDate", "defaultContent" : ""},
				// {"data" : "creater", "defaultContent" : ""},
				// {"data" : "modifyDate", "defaultContent" : ""},
				// {"data" : "modifyer", "defaultContent" : ""},
				{"data" : "stakeholderName", "defaultContent" : ""},
				{"data" : "stakeholderRelationship", "defaultContent" : ""},
                {"data" : "event", "defaultContent" : "",
                    "render": function (data, type, row) {
                        var table = "<table border='1' width='100%' style='text-align: center'><thead style='text-align: center'> " +
                            " <th style='text-align: center'>时间</th> " +
                            " <th style='text-align: center'>事件</th> " +
                            " </thead>" +
                            "<tbody>" ;

                        for (var i =0; i < data.length; i++){
                            var tr = "<tr>";
                            tr += "<td>"+row.eventDate[i]+"</td>"
                            tr += "<td>"+data[i]+"</td>"
                            //tr += "<td>"+data[i].contactId+"</td>"
                            tr += "</tr>"
                            table += tr;
                        }
                        table += "</tbody></table>";
                        return table;
                    },
                    "orderable":false
                },
				{ 
								"data": "", 
								"defaultContent": "",
								"orderable":false,
						        "render": function (data, type, row) {
                		           var id = row['id'];
                		           var href = "updateCustomContactStakeholder.html?id=" + id;
                                   var edit = buttonEdit(href, "", pers);
                		           var del = buttonDel(id, "", pers);
                                   return edit + del;
                  	            }		
							},
                
            ],
           "order": [[ 0, "asc" ]]
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除干系人及事件吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'get',
            url : '/customContactStakeholder/delInfoById/'+id,
            success : function(data) {
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        layer.close(1);
    });
}
$("#searchBt").click(function(){
	example.ajax.reload();
});
function toAdd(){
    var type = $("#type").val();
    var contactId = $("#contactId").val();
    location.href='addCustomContactStakeholder.html?contactId='+contactId+'&type='+type
}
init();
</script>
